<template>
  <div class="modifyPrice" @click.stop="numberCls">
    <div class="header">
      <el-button size="mini" type="primary" @click="preservation('A')">
        {{ $t('btn.save') }}
      </el-button>
    </div>
    <el-tabs v-model="activeName">
      <el-tab-pane :label="$t('market.info')" name="modifyPrice" class="layout">
        <jc-form ref="zrf" :option-value="optionValue" :options="options">
          <el-autocomplete
            v-model.trim="optionValue.fdataValue"
            highlight-first-item
            popper-class="my-autocomplete"
            :fetch-suggestions="querySearch18"
            class="input-width"
            size="mini"
            @focus="getBasicUnit('SX_PAREASON')"
            @select="selUnit"
          >
            <i
              slot="suffix"
              class="el-input__icon el-icon-search"
              @click="unitVisabled=true"
            />
            <template slot-scope="{ item }">
              <div class="name">{{ item.fname }}</div>
            </template>
          </el-autocomplete>
        </jc-form>
        <div style="margin-bottom: 5px">
          <el-button
            :disabled="isDisabled"
            size="mini"
            @click="insertHang"
          >{{ $t('btn.newHang') }}<!--新增行--></el-button>
          <el-button size="mini" :disabled="isDisabled" @click="delHang">{{ $t('btn.delHang') }}<!--删除行--></el-button>
          <el-button
            size="mini"
            :disabled="isDisabled"
            @click="batchFill"
          >{{ $t('btn.batchFill') }}<!--批量填充--></el-button>
        </div>
        <div>
          <jc-table
            :table-data="modifyPriceTable"
            :table-header="modifyPriceHeader"
            table-height="calc(100vh - 290px)"
            serial
            @cellClick="cellClick"
            @rowClick="rowClick"
          >
            <el-table-column
              :label="$t('market.priceList')"
              prop="fpriceList"
              align="center"
              min-width="130px"
            >
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.fpriceList"
                  size="mini"
                  :disabled="isDisabled"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-search"
                    @click="handlePriceList(scope.$index)"
                  />
                </el-input>
              </template>
            </el-table-column>
            <el-table-column
              :label="$t('market.suppliername')"
              prop="fsupplier"
              align="center"
              show-overflow-tooltip
            />
            <el-table-column
              :label="$t('market.fmaterial')"
              prop="fnumber"
              align="center"
              width="150px"
            >
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.fnumber"
                  size="mini"
                  @input="getMateriel(scope.$index, scope.row.fnumber)"
                >
                  <i
                    slot="prefix"
                    class="iconfont icon-jin-rud-ao-bo"
                    @click="sonJumpMateriel(scope.row.fnumber)"
                  />
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-search"
                    @click="handleMateriel(scope.row, scope.$index)"
                  />
                </el-input>
                <div v-if="aotuTab && scope.$index === tableIndex" :class="tableIndex<6 ? 'tabPosit': 'tabPosit1'">
                  <el-table
                    :data="materielDialogData"
                    height="24.8vh"
                    :cell-style="{ padding: '2px 0' }"
                    @row-click="materielSelectRow"
                  >
                    <el-table-column :label="$t('market.fmaterial')" prop="fnumber" align="center" width="120" show-overflow-tooltip />
                    <el-table-column :label="$t('shop.name1')" prop="fname" align="center" show-overflow-tooltip />
                    <el-table-column :label="$t('market.fmodel')" prop="fmodel" align="center" show-overflow-tooltip />
                    <el-table-column :label="$t('shop.specifica')" prop="fspecificaTion" align="center" show-overflow-tooltip />
                    <el-table-column :label="$t('market.funit')" prop="funit" align="center" show-overflow-tooltip />
                  </el-table>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              :label="$t('shop.fname2')"
              prop="fname"
              align="center"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="$t('shop.fspecificaTion')"
              prop="fspecificaTion"
              align="center"
              width="120"
            />
            <el-table-column
              :label="$t('market.fdescripTion')"
              prop="fdescripTion"
              align="center"
              min-width="200px"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="$t('market.fmodel2')"
              prop="fmodel"
              align="center"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="$t('market.funit')"
              prop="funit"
              align="center"
              width="50"
              show-overflow-tooltip
            />
            <el-table-column
              :label="$t('market.currency2')"
              prop="fcurrency"
              align="center"
              width="50"
              show-overflow-tooltip
            />
            <el-table-column
              :label="$t('market.formerPrice')"
              prop="fprice"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.fprice"
                  size="mini"
                  :precision="4"
                  :step="0.0001"
                  :min="0.0"
                  disabled
                />
              </template>
            </el-table-column>
            <el-table-column
              :label="$t('market.afterPrice')"
              prop="fafterPrice"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.fafterPrice"
                  size="mini"
                  :precision="4"
                  :step="0.0001"
                  :min="0.0"
                  :disabled="scope.row.fisIncludedTax"
                  @change="handlePrice(scope.row)"
                />
              </template>
            </el-table-column>
            <el-table-column
              :label="$t('market.formerTaxPrice')"
              prop="ftaxPrice"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.ftaxPrice"
                  size="mini"
                  :precision="4"
                  :step="0.0001"
                  :min="0.0"
                  disabled
                />
              </template>
            </el-table-column>
            <el-table-column
              :label="$t('market.afterTaxPrice')"
              prop="fafterTaxPrice"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.fafterTaxPrice"
                  size="mini"
                  :precision="4"
                  :step="0.0001"
                  :min="0.0"
                  :disabled="!scope.row.fisIncludedTax"
                  @change="handleTaxIncluded(scope.row)"
                />
              </template>
            </el-table-column>
            <el-table-column
              :label="$t('market.formerRate')"
              prop="ftaxRate"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.ftaxRate"
                  size="mini"
                  :precision="4"
                  :step="0.0001"
                  :min="0.0"
                  disabled
                />
              </template>
            </el-table-column>
            <el-table-column
              :label="$t('market.afterRate')"
              prop="fafterTaxRate"
              align="center"
            >
              <!--              <template slot-scope="scope">-->
              <!--                <el-input-number-->
              <!--                  v-model="scope.row.fafterTaxRate"-->
              <!--                  size="mini"-->
              <!--                  :precision="4"-->
              <!--                  :step="0.0001"-->
              <!--                  :min="0.0"-->
              <!--                  @change="handleTaxRate(scope.row)"-->
              <!--                />-->
              <!--              </template>-->
            </el-table-column>
            <el-table-column :label="$t('market.tax')" prop="fisIncludedTax" align="center" width="30">
              <template slot-scope="scope">
                <el-checkbox v-model="scope.row.fisIncludedTax" disabled />
              </template>
            </el-table-column>
            <!-- 生效时间 -->
            <template v-slot:btnState="col">
              <el-date-picker
                v-model="col.scope.row.feffectiveDate"
                type="date"
                value-format="yyyy-MM-dd"
                size="mini"
                :disabled="isDisabled"
                style="width: 163px"
              />
            </template>
            <!-- 失效时间 -->
            <template v-slot:btnStates="col">
              <el-date-picker
                v-model="col.scope.row.fexpiryDate"
                type="date"
                value-format="yyyy-MM-dd"
                size="mini"
                :disabled="isDisabled"
                style="width: 163px"
              />
            </template>
            <!-- 备注 -->
            <template v-slot:text2Slot="col">
              <el-input
                v-model="col.scope.row.fnote"
                size="mini"
                :disabled="isDisabled"
              />
            </template>
          </jc-table>
        </div>
      </el-tab-pane>
    </el-tabs>
    <!--    采购价目列表-->
    <purPrice v-if="openPriceList" @purchase="priceListSelectRow" />
    <!--    物料编码列表-->
    <jc-popup
      v-model="materielPagination.fnumber"
      :dialog-title="$t('shop.fnumber1')"
      :open-dialog="openMaterial"
      :popup-title="popupTitle"
      @closeDialog="closeDialog"
      @emptyForm="emptyForm"
      @handleSearch="getMateriel"
    >
      <template v-slot:content>
        <div>
          <jc-table
            :table-data="materielDialogData"
            :table-header="materielDialogHeader"
            table-height="500px"
            serial
            @clickRow="materielSelectRow"
          />
        </div>
      </template>
      <template v-slot:pagination>
        <jc-pagination
          v-show="materielPagination.total > 0"
          :total="materielPagination.total"
          :page.sync="materielPagination.pageNum"
          :limit.sync="materielPagination.pageSize"
          @pagination="getMateriel"
        />
      </template>
    </jc-popup>
    <!--  数据字典弹窗  -->
    <unit v-if="unitVisabled" :msg="funit" @unit="selUnit" />
  </div>
</template>

<script>
import jcForm from '@/components/Form'
import jcPopup from '@/views/basic/createMateriel2/components/Popup'
import { queryTOrgOrganizationsL } from '@/api/engineering/createBom'
import {
  insertTPurPat,
  queryTPurPatMatList
} from '@/api/modifyPriceManagement/createModifyPrice'
import jumpMateriel from '@/components/JumpMateriel'
import { queryTPurPatDetailList } from '@/api/modifyPriceManagement/detailModifyPrice'
import { toMxAmina } from '@/components/ToMxamineState'
import autocomplete from '@/views/market/marketManage/createMarkerOrder/components/autocomplete'

export default {
  name: 'CreateModifyPrice',
  components: {
    jcForm,
    jcPopup,
    purPrice: () => import('@/views/purchasing/modifyPrice/components/purPrice'),
    unit: () => import('@/views/basic/createMateriel2/components/unit')
  },
  mixins: [jumpMateriel, autocomplete],
  props: {
    modify: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      radio2: '新增',
      activeName: 'modifyPrice',
      dialogTitle: '', // 弹窗名称
      unitVisabled: false,
      funit: 'SX_PAREASON',
      openModifyPrice: false, // 采购调价原因列表弹窗
      openMaterial: false, // 物料编码弹窗
      openPriceList: false, // 采购价目弹窗
      popupTitle: '', // 弹窗名称
      teamList: [], // 组织数
      isDisabled: false,
      aotuTab: false,
      modifyPriceTable: [
        {
          fid: this.modify.fid || '', // 价目ID
          fmaterialId: '', // 物料ID
          fname: this.modify.fname || '', // 价目表
          fisIncludedTax: this.modify.fisIncludedTax || false, // 含税
          fnumber: '', // 物料编码
          fafterPrice: '', // 调后单价
          fafterTaxPrice: '', // 调后含税单价
          fafterTaxRate: '', // 调后税率
          fsupplier: this.modify.fsupplier || '', // 供应商名称
          fcurrency: this.modify.fcurrency || '', // 币别
          fdescripTion: '', // 描述
          fspecificaTion: '', // 规格型号
          fprice: '', // 调前单价
          ftaxPrice: '', // 调前含税单价
          ftaxRate: '', // 调前税率
          fupPrice: 0, // 上限
          fdownPrice: 0, // 下限
          feffectiveDate: new Date(), // 生效时间
          fexpiryDate: '2100-01-01' // 失效时间
        }
      ], // 调价表数据
      modifyPriceHeader: [
        {
          label: this.$t('market.topPrice'),
          prop: 'fupPrice',
          width: '80'
        },
        {
          label: this.$t('market.downPrice'),
          prop: 'fdownPrice',
          width: '80'
        },
        {
          label: this.$t('market.effectiveDate'),
          prop: 'feffectiveDate',
          type: 'state',
          width: '120'
        },
        {
          label: this.$t('market.expiryDate'),
          prop: 'fexpiryDate',
          type: 'states',
          width: '120'
        },
        {
          label: this.$t('market.note'),
          prop: 'fnote',
          type: 'text2',
          width: '120'
        }
      ],
      // 物料编码数据
      materielDialogData: [],
      // 物料编码表头
      materielDialogHeader: [
        { label: this.$t('market.fmaterial'), prop: 'fnumber' },
        { label: this.$t('shop.fname2'), prop: 'fname' },
        { label: this.$t('shop.fspecificaTion'), prop: 'fspecificaTion' },
        { label: this.$t('market.fmodel'), prop: 'fmodel' },
        { label: this.$t('market.fdescripTion'), prop: 'fdescripTion', minWidth: '200px' },
        { label: this.$t('market.formerPrice'), prop: 'fprice' },
        {
          label: this.$t('market.formerTaxPrice'),
          prop: 'ftaxPrice'
        },
        {
          label: this.$t('market.formerRate'),
          prop: 'ftaxRate'
        }
      ],
      // 物料弹窗分页
      materielPagination: {
        total: 0, // 总条目
        pageNum: 1, // 当前页
        pageSize: 200, // 每页显示多少条数据
        fnumber: '', // 物料编码
        fid: '' // 价目ID
      },
      optionValue: {}, // 表单值
      options: {}, // 表单控件
      tableIndex: 0, // 表格序号
      nary: []
    }
  },
  created() {
    if (this.$route.query.fid) {
      this.optionValue.fid = this.$route.query.fid
      this.getFormTo()
    } else {
      this.getForm()
    }
  },
  methods: {
    numberCls() {
      if (this.aotuTab) {
        this.modifyPriceTable[this.tableIndex].fnumber = ''
      }
      this.aotuTab = false
    },
    // 保存
    preservation(ev) {
      const validDate = this.$refs.zrf.handleRefData()
      if (!validDate) {
        return
      }
      for (const ITEM of this.modifyPriceTable) {
        if (
          !ITEM.fid ||
          !ITEM.fmaterialId
        ) {
          this.$message.warning('表格不能为空,或表格值不能为0')
          return
        }
      }
      this.nary = []
      const DETAILS = this.modifyPriceTable.map(item => {
        this.nary.push(item.fnumber)
        const {
          fnote,
          fmaterialId,
          fisIncludedTax,
          fafterPrice,
          fafterTaxPrice,
          fafterTaxRate,
          fupPrice,
          fprice,
          fname,
          ftaxPrice,
          ftaxRate,
          funitId,
          fsupplierId,
          fcurrencyId,
          fdownPrice,
          feffectiveDate,
          fexpiryDate,
          fsrcentryId
        } = item
        return {
          fnote,
          fname,
          funitId,
          fsupplierId,
          fcurrencyId,
          fsrcentryId,
          fisIncludedTax,
          fpriceListId: item.fid,
          fmaterialId,
          fprice,
          ftaxPrice,
          ftaxRate,
          fafterPrice,
          fafterTaxPrice,
          fafterTaxRate,
          fupPrice,
          fdownPrice,
          feffectiveDate,
          fexpiryDate
        }
      })
      const nary = this.nary.sort()
      for (const index in this.nary) {
        const index1 = Number(index) + 1 * 1
        if (nary[index] === nary[index1]) {
          this.$message.warning('重复的物料：' + nary[index])
          return false
        }
      }
      const { fname, fdescription, fpaReason, fid, fdate } = this.optionValue
      const DATA = {
        fid,
        fdate,
        fname,
        fdescription,
        fpaReason,
        fdocumentStatus: ev, // 保存A,提交B
        details: DETAILS
      }
      insertTPurPat(DATA)
        .then(res => {
          if (res.code !== 0) {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
            return
          }
          this.optionValue.billCode = res.data.fbillNo
          this.optionValue.fid = res.data.fid
          if (res.code !== 0) {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
            return
          }
          this.getForm()
          this.modifyPriceTable = []
          // 关闭当前页面
          this.$store.dispatch('tagsView/guanbi', this.$route)
          // 跳转到修改页面
          this.$router.push({ path: `/editModifyPrice/${res.data}` })
          this.$message({ showClose: true, message: res.message, type: 'success' })
        })
        .catch(error => {
          this.$message.error(error)
        })
    },
    // 调前单价
    handlePrice(row) {
      // 价格上限 fupPrice、价格下限 fdownPrice、调后含税单价 fafterTaxPrice 调后单价 fafterPrice
      const { fafterPrice, fafterTaxRate } = row
      row.fafterTaxPrice = (fafterPrice * (1 + fafterTaxRate / 100)).toFixed(4)
      row.fupPrice = row.fafterTaxPrice
      row.fdownPrice = row.fafterTaxPrice
    },
    // 调前含税单价
    handleTaxIncluded(row) {
      const { fafterTaxPrice, fafterTaxRate } = row
      row.fafterPrice = (fafterTaxPrice / (1 + fafterTaxRate / 100)).toFixed(4)
      row.fupPrice = row.fafterTaxPrice
      row.fdownPrice = row.fafterTaxPrice
    },
    // 调后税率
    handleTaxRate(row) {
      const { fisIncludedTax, fafterPrice, fafterTaxRate, fafterTaxPrice } = row
      if (!fisIncludedTax) {
        // 单价
        row.fafterTaxPrice = (fafterPrice * (1 + fafterTaxRate / 100)).toFixed(4)
        row.fupPrice = row.fafterTaxPrice
        row.fdownPrice = row.fafterTaxPrice
      } else {
        // 含税单价
        row.fafterPrice = (fafterTaxPrice / (1 + fafterTaxRate / 100)).toFixed(4)
        row.fupPrice = row.fafterTaxPrice
        row.fdownPrice = row.fafterTaxPrice
      }
    },
    // 获取价目表
    priceListSelectRow(item) {
      if (item?.fid) {
        const { fname, fsupplier, fisIncludedTax, fcurrency, ftaxrate, fid, fsupplierId, fcurrencyId } = item
        const modifyPriceTable = this.modifyPriceTable[this.tableIndex]
        modifyPriceTable.fpriceList = fname
        modifyPriceTable.fsupplier = fsupplier
        modifyPriceTable.fisIncludedTax = fisIncludedTax
        modifyPriceTable.fcurrency = fcurrency
        modifyPriceTable.fcurrencyId = fcurrencyId
        modifyPriceTable.fid = fid
        modifyPriceTable.fsupplierId = fsupplierId
        modifyPriceTable.fafterTaxRate = ftaxrate
        // 物料编码
        modifyPriceTable.fmaterialId = ''
        modifyPriceTable.fnumber = ''
      }
      this.openPriceList = false
    },
    // 获取物料编码
    materielSelectRow(item) {
      const modifyPriceTable = this.modifyPriceTable[this.tableIndex]
      const {
        fmaterialId,
        fnumber,
        fname,
        fmodel,
        funit,
        funitId,
        fspecificaTion,
        fdescripTion,
        fprice,
        ftaxPrice,
        ftaxRate,
        fsrcentryId
      } = item
      modifyPriceTable.fmaterialId = fmaterialId
      modifyPriceTable.fnumber = fnumber
      modifyPriceTable.fname = fname
      modifyPriceTable.fmodel = fmodel
      modifyPriceTable.funit = funit
      modifyPriceTable.funitId = funitId
      modifyPriceTable.fspecificaTion = fspecificaTion
      modifyPriceTable.fdescripTion = fdescripTion
      modifyPriceTable.fprice = fprice
      modifyPriceTable.ftaxPrice = ftaxPrice
      modifyPriceTable.ftaxRate = ftaxRate
      modifyPriceTable.fsrcentryId = fsrcentryId
      this.openMaterial = false
      this.aotuTab = false
    },
    // 物料列表
    async getMateriel(index, fnumber) {
      if (index || index === 0) {
        this.tableIndex = index
        this.aotuTab = true
      }
      const { data: RES } = await queryTPurPatMatList({
        ...this.materielPagination,
        fid: this.modifyPriceTable[this.tableIndex].fid,
        fnumber: fnumber || this.materielPagination.fnumber
      })
      const { array, list } = RES
      this.materielDialogData = list
      this.materielPagination.total = array
    },
    // 获取物料编码
    async handleMateriel(row, index) {
      this.tableIndex = index
      if (!row.fid) {
        this.$message.warning('价目表未选择或数据出错,请重新选择')
        return
      }
      this.materielPagination.fid = this.modifyPriceTable[this.tableIndex].fid
      this.openMaterial = true
      this.dialogTitle = '物料编码列表'
      this.popupTitle = '物料编码'
      this.getMateriel()
    },
    // 价目表
    handlePriceList(index) {
      this.tableIndex = index
      this.openPriceList = true
      this.popupTitle = '供应商名称'
    },
    // 关闭弹窗
    closeDialog() {
      this.materielPagination.pageNum = 1
      this.openPriceList = false
      this.openModifyPrice = false
      this.openMaterial = false
    },
    // 清空弹窗表单
    emptyForm() {
      this.materielPagination.fnumber = ''
      this.materielPagination.pageNum = 1
    },
    // 调价原因
    selUnit(ev) {
      if (ev.fid) {
        this.optionValue.fdataValue = ev.fname
        this.optionValue.fpaReason = ev.fid
      }
      this.unitVisabled = false
    },
    // 删除行数据
    handleDelete(index) {
      this.modifyPriceTable.splice(index, 1)
      this.$message.success('删除行成功')
    },
    // 获取表格
    async getForm() {
      this.optionValue = {
        fdate: new Date(),
        fdocumentStatus: '创建', // 单据状态
        fdataValue: '', // 调价原因名称
        fpaReason: '', // 调价原因id
        fname: '', // 名称
        billCode: '', // 单据编号
        fdescription: '' // 描述
      }
      this.options = {
        fpaReason: {
          label: this.$t('market.paReason'),
          type: 'slot',
          span: 6
        },
        fname: {
          label: this.$t('shop.name1'),
          span: 6,
          rules: [{ required: true }]
        },
        billCode: {
          label: this.$t('market.billNo'),
          span: 6,
          disabled: 'disabled'
        },
        fdocumentStatus: {
          label: this.$t('market.documentstatus'),
          type: 'tag',
          labelWidth: '100px',
          span: 6,
          disabled: 'disabled'
        },
        fdate: {
          label: this.$t('market.placedate'),
          type: 'date',
          span: 6
        },
        fdescription: {
          label: this.$t('market.note'),
          span: 6
          // rules: [{ required: true }]
        }
      }
    },
    // 获取详情(复制)
    async getFormTo() {
      const { data: RES } = await queryTPurPatDetailList({
        fid: this.optionValue.fid
      })
      this.modifyPriceTable = RES.detail
      const { data: TEAMlIST } = await queryTOrgOrganizationsL()
      this.teamList = TEAMlIST.map(item => {
        const { fname: label, fpkId: value } = item
        return { label, value }
      })
      const { fdataValue, fid, fname, fbillno, fdescripTion, fdocumentStatus, fdate, fpaReason } = toMxAmina(RES)
      this.optionValue = {
        fid,
        fdate,
        fdocumentStatus, // 状态
        fdataValue, // 调价原因名称
        fpaReason, // 调价原因id
        fname, // 名称
        billCode: fbillno, // 单据编号
        fdescription: fdescripTion // 描述
      }
      this.isDisabled = this.optionValue.fdocumentStatus === this.$t('market.state1') || this.optionValue.fdocumentStatus === this.$t('market.state2')
      this.options = {
        fdocumentStatus: {
          label: this.$t('market.documentstatus'),
          span: 6,
          disabled: 'disabled'
        },
        fdataValue: {
          label: this.$t('market.paReason'),
          type: 'slot',
          disabled: this.isDisabled,
          span: 6
        },
        fname: {
          label: this.$t('shop.name1'),
          span: 6,
          disabled: this.isDisabled
        },
        billCode: {
          label: this.$t('market.billNo'),
          span: 6,
          disabled: 'disabled'
        },
        fdate: {
          type: 'date',
          label: this.$t('market.placedate'),
          disabled: this.isDisabled,
          span: 6
        },
        fdescription: {
          label: this.$t('market.note'),
          span: 12,
          disabled: this.isDisabled
        }
      }
    },
    // 点击单元格
    cellClick(row, column) {
      this.property = column.property
      this.subscript = row.index
    },
    // 批量填充
    batchFill() {
      const item = this.modifyPriceTable[this.subscript][this.property]
      this.modifyPriceTable.map((res, index) => {
        if (index >= this.subscript) {
          res[this.property] = item
          if (this.property === 'fpriceList') {
            res.fid = this.modifyPriceTable[0].fid
            res.fafterTaxRate = this.modifyPriceTable[0].fafterTaxRate
            res.fpriceList = this.modifyPriceTable[0].fpriceList
            res.fsupplier = this.modifyPriceTable[0].fsupplier
            res.fsupplierId = this.modifyPriceTable[0].fsupplierId
            res.fisIncludedTax = this.modifyPriceTable[0].fisIncludedTax
            res.fcurrency = this.modifyPriceTable[0].fcurrency
            res.fcurrencyId = this.modifyPriceTable[0].fcurrencyId
          } else if (this.property === 'fafterPrice') {
            this.handlePrice(res)
          } else if (this.property === 'fafterTaxRate') {
            this.handleTaxRate(res)
          } else if (this.property === 'fafterTaxPrice') {
            this.handleTaxIncluded(res)
          }
        }
      })
    },
    // 单击行
    rowClick(row) {
      this.indexSelf = row.index
    },
    // 删除行
    delHang() {
      this.modifyPriceTable.splice(this.indexSelf, 1)
    },
    // 新增插入行
    insertHang() {
      const data = {
        funit: '',
        fnote: '',
        fid: this.modify.fid || '', // 价目ID
        fmaterialId: '', // 物料ID
        fname: this.modify.fname || '', // 价目表
        fisIncludedTax: this.modify.fisIncludedTax || false, // 含税
        fnumber: '', // 物料编码
        fafterPrice: '', // 调后单价
        fafterTaxPrice: '', // 调后含税单价
        fafterTaxRate: 0, // 调后税率
        fsupplier: this.modify.fsupplier || '', // 供应商名称
        fcurrency: this.modify.fcurrency || '', // 币别
        fdescripTion: '', // 描述
        fspecificaTion: '', // 规格型号
        fprice: '', // 调前单价
        ftaxPrice: '', // 调前含税单价
        ftaxRate: '', // 调前税率
        fupPrice: 0, // 上限
        fdownPrice: 0, // 下限
        feffectiveDate: new Date(), // 生效时间
        fexpiryDate: '2100-01-01' // 失效时间
      }
      this.modifyPriceTable.push(data)
    }
  }
}
</script>

<style scoped lang="scss">
.modifyPrice {
  @include listBom;
  display: flex;
  flex-direction: column;

  .header {
    margin-bottom: 0.62vh;
  }
  .tabPosit {
    padding: 5px;
    box-shadow: 0 0 2px #aaa;
    position: absolute;
    top: 3.8vh;
    left: 0;
    background-color: rgba(255, 255, 255, 1);
    z-index: 9999;
  }
  .tabPosit1 {
    padding: 5px;
    box-shadow: 0 0 2px #aaa;
    position: absolute;
    top: -25.69vh;
    left: 0;
    background-color: rgba(255, 255, 255, 1);
    z-index: 9999;
  }
  .layout {
    display: flex;
    flex-direction: column;

    .input-width {
      width: 100%;
      max-width: 185px;
    }
  }
}

.el-input__icon {
  cursor: pointer;
}

.icon-jin-rud-ao-bo {
  cursor: pointer;

  &:hover {
    color: #409eff;
  }
}
</style>
